using UnityEngine;
using System.Collections;

public class Indio : DrawableGameObject 
{
	public Texture2D[] attackTextures;
	public GameObject arrow;
	public GameObject arrowSpawner;
	private bool isChecked;
    private GameObject character;
    public float interval = 9;

	public override void Start () 
	{
        character = GameObject.FindWithTag("Player");

		base.SetAnimations(null, null, null, null, attackTextures);
		base.Start();
	}
	
	public void Update () 
	{
        if (Mathf.Abs(character.transform.position.x - transform.position.x) < interval)
        {
            RunAnimation();
        }
        else
        {
            base.StopAnimation();
        }
		
		if(gameObject.renderer.material.mainTexture == attackTextures[13] && isChecked == false)
		{
			Shoot();
			isChecked = true;
		}
		
		if(gameObject.renderer.material.mainTexture != attackTextures[13])
		{
			isChecked = false;
		}
	}
	
	public void RunAnimation()
	{
		base.RunAnimation("Attack", "Loop");
	}
	
	public void Shoot()
	{
		Instantiate(arrow, arrowSpawner.transform.position, Quaternion.identity);
	}
}
